<?php

$auth = @$_SESSION['auth'];
if (empty($auth)) die('用户未登录！^_^');

if (!dt_query_one("SELECT id FROM account_addr WHERE name !='' AND addr != '' AND p_code != '' AND phone != '' AND id = ".$auth['id']." LIMIT 1")) die('e1');

$topic_id = intval($_GET['topic_id']);

$cond = "WHERE user_id = ".$auth['id']." AND topic_id = $topic_id";

if (!dt_query_one("SELECT id FROM forum_topic_order $cond LIMIT 1")) {
	$rs = dt_query("INSERT INTO forum_topic_order (user_id, topic_id, c_at) VALUES (".$auth['id'].", $topic_id, ".time().")");
	if (!$rs) die('新增数据失败！');
	$rs = dt_query("UPDATE forum_topic SET order_c = order_c + 1 WHERE id = $topic_id");
	if (!$rs) die('统计数据失败！');
	die('s0');
} else {
	$rs = dt_query("DELETE FROM forum_topic_order $cond");
	if (!$rs) die('删除数据失败！');
	$rs = dt_query("UPDATE forum_topic SET order_c = order_c - 1 WHERE order_c > 0 AND id = $topic_id");
	if (!$rs) die('统计数据失败！');
	die('s1');
}
